package com.lebang.service;

import com.lebang.domain.MemberSdkBanned;
import com.lebang.example.MemberSdkBannedExample;
import com.lebang.mapper.MemberSdkBannedMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author ljx
 * @date 2020/12/22
 */
@Service
public class MemberSdkBannedService extends BaseService<MemberSdkBanned,Integer, MemberSdkBannedExample> {
    @Autowired
    private MemberSdkBannedMapper mapper;

    /**
     * 添加封禁记录
     * @return
     */
    public boolean addRecord(String memberId,String sdkKey,String cause){
        Integer count=mapper.countByMemberIdAndSdkKey(memberId,sdkKey);
        if (count > 0){
            return false;
        }
        MemberSdkBanned banned=new MemberSdkBanned();
        banned.setCreateTime(LocalDateTime.now());
        banned.setMemberId(memberId);
        banned.setSdkKey(sdkKey);
        banned.setCause(cause);
        mapper.insert(banned);
        return true;
    }

    /**
     * 删除封禁记录
     * @return
     */
    public Integer delRecord(String memberId,String sdkKey){
        MemberSdkBannedExample example=new MemberSdkBannedExample();
        example.createCriteria().andMemberIdEqualTo(memberId).andSdkKeyEqualTo(sdkKey);
        return mapper.deleteByExample(example);
    }

    /**
     * 获取用户封禁数据源
     */
    public List<String> getRecord(String memberId){
        return mapper.getRecord(memberId);
    }
}
